package ldkxingzhe.ldkxingzhedemo.service;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * Created by ke on 15-9-13.
 */
public class MessengerClientActivity extends AppCompatActivity implements View.OnClickListener {
    private final String TAG = MessengerClientActivity.class.getSimpleName();

    private MessengerClientFragment messengerClientFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        String[] buttonName = new String[]{
          "bindService","unBindService","sendSimpleData","sendComplexData"
        };
        for(int i = 0; i < buttonName.length; i++){
            Button button = new Button(this);
            button.setText(buttonName[i]);
            button.setTag(i);
            button.setOnClickListener(this);
            layout.addView(button);
        }
        setContentView(layout);
        messengerClientFragment = (MessengerClientFragment)getSupportFragmentManager()
                .findFragmentByTag("messengerClientFragment");
        if(messengerClientFragment == null){
            messengerClientFragment = MessengerClientFragment.newInstance();
            getSupportFragmentManager().beginTransaction()
                    .add(messengerClientFragment,"messengerClientFragment")
                    .commit();
        }
    }

    @Override
    public void onClick(View v) {
        switch ((int)v.getTag()){
            case 0:
                messengerClientFragment.doBindService();
                break;
            case 1:
                messengerClientFragment.doUnbindService();
                break;
            case 2:
                messengerClientFragment.doSendSimpleData();
                break;
            case 3:
                break;
            default:
                break;
        }
    }
}
